package view.backing.Utils.Validator;

import chemtools_logica.Beans.PersonaBean;

import chemtools_logica.Beans.RolBean;

import chemtools_logica.LN.IR.LN_SFPersonaRemote;

import chemtools_logica.LN.IR.LN_SFRolRemote;

import java.util.Hashtable;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class nombreRolValidator implements Validator {
    public nombreRolValidator() {
        super();
    }
    LN_SFRolRemote lN_SFRolRemote;
    
    @Override
    public void validate(FacesContext facesContext, UIComponent uIComponent, Object object) throws ValidatorException {
        try {
            final Context context = getInitialContext();
            lN_SFRolRemote = (LN_SFRolRemote) context.lookup("map-LN_SFRol#chemtools_logica.LN.IR.LN_SFRolRemote"); 
        }catch(NamingException e){return;}
        
        RolBean r=new RolBean();
        r.setNombre(object.toString());
        r.setEstado(-1);
        if(lN_SFRolRemote.buscarRolExacto(r).size()>0){
        FacesMessage fm = new FacesMessage("El Nombre de Rol ya Existe");
        throw new ValidatorException(fm);
        }
        }
        private static Context getInitialContext() throws NamingException {
        Hashtable env = new Hashtable();
        // WebLogic Server 10.x/12.x connection details
        env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
        env.put(Context.PROVIDER_URL, "t3://127.0.0.1:7101");
        return new InitialContext(env);
        }
}
